package com.dmall.controller;

import com.alibaba.fastjson.JSON;
import com.dmall.pojo.User;
import com.dmall.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用户管理Controller
 * @author xiao1.wang
 * @date 2019-06-25 13:39:51
 */
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/master/list")
    public List<User> masterList() {
        return userService.masterList();
    }

    @GetMapping("/save")
    public String saveUser(User user) throws Exception {
        String desc = new String(user.getDesc().getBytes("ISO8859-1"), "UTF-8");
        user.setDesc(desc);
        log.info("UserController#saveUser user={}", JSON.toJSONString(user));
        userService.saveUser(user);
        return "success";
    }

    @GetMapping("/slave/list")
    public List<User> slaveList() {
        return userService.slaveList();
    }
}
